package com.chiaching.framwork.utils;

import lombok.extern.slf4j.Slf4j;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.select.Elements;

/**
 * @author jiajing.he
 * @date 2021/7/28 上午11:32
 */
@Slf4j
public class IPUtils {

    /**
     * 获取公网ip地址
     * @return
     */
    public static String openIPAddress(){
        try {
            // 打开连接
            Document doc = Jsoup.connect("http://chaipip.com/").get();
            Elements eles = doc.select("#ip");
            return eles.attr("value");
        } catch (Exception e) {
            log.error("获取公网IP地址异常",e);
        }
        return "";
    }
}
